const todos = (state = [], action) => {
  switch (action.type) {
    case "ADD_TODO":
      console.log("数据新增：", action);
      return [
        ...state,
        {
          id: action.id,
          text: action.text,
          completed: false,
        },
      ];
    case "TOGGLE_TODO":
      return state.map((item) => {
        if (item.id === action.id) {
          return { ...item, completed: !item.completed };
        } else {
          return item;
        }
      });
    default:
      return state;
  }
};

export default todos;
